-
Notifications
You must be signed in to change notification settings - Fork 14.4k
llvm-profgen: Options cleanup / fixes #147632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MatzeB
wants to merge
2
commits into
llvm:main
Choose a base branch
from
MatzeB:profgen_options
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+133
−101
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Note that this includes the changes of #147631 |
✅ With the latest revision this PR passed the C/C++ code formatter. |
(global) `using namespace` directives in headers are bad style.
- Add cl::cat(ProfGenCategory) where missing so the options show up in --help output. - Introduce `Options.h` to shared declarations for options referenced in multiple files.
@llvm/pr-subscribers-pgo Author: Matthias Braun (MatzeB) Changes
Patch is 20.71 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/147632.diff 11 Files Affected:
diff --git a/llvm/tools/llvm-profgen/CSPreInliner.h b/llvm/tools/llvm-profgen/CSPreInliner.h
index 8a3f16a4f13cb..022c3f8d0daed 100644
--- a/llvm/tools/llvm-profgen/CSPreInliner.h
+++ b/llvm/tools/llvm-profgen/CSPreInliner.h
@@ -16,9 +16,6 @@
#include "llvm/Transforms/IPO/ProfiledCallGraph.h"
#include "llvm/Transforms/IPO/SampleContextTracker.h"
-using namespace llvm;
-using namespace sampleprof;
-
namespace llvm {
namespace sampleprof {
diff --git a/llvm/tools/llvm-profgen/ErrorHandling.h b/llvm/tools/llvm-profgen/ErrorHandling.h
index b797add8a892f..17084bd785e64 100644
--- a/llvm/tools/llvm-profgen/ErrorHandling.h
+++ b/llvm/tools/llvm-profgen/ErrorHandling.h
@@ -16,7 +16,7 @@
#include "llvm/Support/WithColor.h"
#include <system_error>
-using namespace llvm;
+namespace llvm {
[[noreturn]] inline void exitWithError(const Twine &Message,
StringRef Whence = StringRef(),
@@ -53,4 +53,6 @@ inline void emitWarningSummary(uint64_t Num, uint64_t Total, StringRef Msg) {
<< "%(" << Num << "/" << Total << ") " << Msg << "\n";
}
+} // end namespace llvm
+
#endif
diff --git a/llvm/tools/llvm-profgen/MissingFrameInferrer.cpp b/llvm/tools/llvm-profgen/MissingFrameInferrer.cpp
index edfe8979c7121..7ebca23ba7956 100644
--- a/llvm/tools/llvm-profgen/MissingFrameInferrer.cpp
+++ b/llvm/tools/llvm-profgen/MissingFrameInferrer.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "MissingFrameInferrer.h"
+#include "Options.h"
#include "PerfReader.h"
#include "ProfiledBinary.h"
#include "llvm/ADT/SCCIterator.h"
@@ -37,7 +38,8 @@ STATISTIC(TailCallMaxTailCallPath, "Length of the longest tail call path");
static cl::opt<uint32_t>
MaximumSearchDepth("max-search-depth", cl::init(UINT32_MAX - 1),
cl::desc("The maximum levels the DFS-based missing "
- "frame search should go with"));
+ "frame search should go with"),
+ cl::cat(ProfGenCategory));
void MissingFrameInferrer::initialize(
const ContextSampleCounterMap *SampleCounters) {
diff --git a/llvm/tools/llvm-profgen/Options.h b/llvm/tools/llvm-profgen/Options.h
new file mode 100644
index 0000000000000..f94cf9118c06a
--- /dev/null
+++ b/llvm/tools/llvm-profgen/Options.h
@@ -0,0 +1,28 @@
+//===-- Options.h -----------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_LLVM_PROFGEN_OPTIONS_H
+#define LLVM_TOOLS_LLVM_PROFGEN_OPTIONS_H
+
+#include "llvm/Support/CommandLine.h"
+
+namespace llvm {
+
+extern cl::OptionCategory ProfGenCategory;
+
+extern cl::opt<std::string> OutputFilename;
+extern cl::opt<bool> ShowDisassemblyOnly;
+extern cl::opt<bool> ShowSourceLocations;
+extern cl::opt<bool> SkipSymbolization;
+extern cl::opt<bool> ShowDetailedWarning;
+extern cl::opt<bool> InferMissingFrames;
+extern cl::opt<bool> EnableCSPreInliner;
+extern cl::opt<bool> UseContextCostForPreInliner;
+
+} // end namespace llvm
+
+#endif
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index ad113eda27914..7e045b0c06229 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
#include "PerfReader.h"
+
+#include "Options.h"
#include "ProfileGenerator.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
@@ -15,44 +17,47 @@
#define DEBUG_TYPE "perf-reader"
+namespace llvm {
+
cl::opt<bool> SkipSymbolization("skip-symbolization",
cl::desc("Dump the unsymbolized profile to the "
"output file. It will show unwinder "
- "output for CS profile generation."));
+ "output for CS profile generation."),
+ cl::cat(ProfGenCategory));
static cl::opt<bool> ShowMmapEvents("show-mmap-events",
- cl::desc("Print binary load events."));
+ cl::desc("Print binary load events."),
+ cl::cat(ProfGenCategory));
static cl::opt<bool>
UseOffset("use-offset", cl::init(true),
cl::desc("Work with `--skip-symbolization` or "
"`--unsymbolized-profile` to write/read the "
- "offset instead of virtual address."));
+ "offset instead of virtual address."),
+ cl::cat(ProfGenCategory));
static cl::opt<bool> UseLoadableSegmentAsBase(
"use-first-loadable-segment-as-base",
cl::desc("Use first loadable segment address as base address "
"for offsets in unsymbolized profile. By default "
- "first executable segment address is used"));
+ "first executable segment address is used"),
+ cl::cat(ProfGenCategory));
static cl::opt<bool>
IgnoreStackSamples("ignore-stack-samples",
cl::desc("Ignore call stack samples for hybrid samples "
- "and produce context-insensitive profile."));
+ "and produce context-insensitive profile."),
+ cl::cat(ProfGenCategory));
cl::opt<bool> ShowDetailedWarning("show-detailed-warning",
- cl::desc("Show detailed warning message."));
+ cl::desc("Show detailed warning message."),
+ cl::cat(ProfGenCategory));
static cl::opt<int> CSProfMaxUnsymbolizedCtxDepth(
"csprof-max-unsymbolized-context-depth", cl::init(-1),
cl::desc("Keep the last K contexts while merging unsymbolized profile. -1 "
- "means no depth limit."));
+ "means no depth limit."),
+ cl::cat(ProfGenCategory));
-extern cl::opt<std::string> PerfTraceFilename;
-extern cl::opt<bool> ShowDisassemblyOnly;
-extern cl::opt<bool> ShowSourceLocations;
-extern cl::opt<std::string> OutputFilename;
-
-namespace llvm {
namespace sampleprof {
void VirtualUnwinder::unwindCall(UnwindState &State) {
diff --git a/llvm/tools/llvm-profgen/PerfReader.h b/llvm/tools/llvm-profgen/PerfReader.h
index 4b3ac8f569755..19451915812e1 100644
--- a/llvm/tools/llvm-profgen/PerfReader.h
+++ b/llvm/tools/llvm-profgen/PerfReader.h
@@ -17,9 +17,6 @@
#include <fstream>
#include <map>
-using namespace llvm;
-using namespace sampleprof;
-
namespace llvm {
class CleanupInstaller;
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index db686c3b597eb..33575b9c67625 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -8,6 +8,7 @@
#include "ProfileGenerator.h"
#include "ErrorHandling.h"
#include "MissingFrameInferrer.h"
+#include "Options.h"
#include "PerfReader.h"
#include "ProfiledBinary.h"
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
@@ -17,20 +18,24 @@
#include <unordered_set>
#include <utility>
+namespace llvm {
+
cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
cl::Required,
- cl::desc("Output profile file"));
+ cl::desc("Output profile file"),
+ cl::cat(ProfGenCategory));
static cl::alias OutputA("o", cl::desc("Alias for --output"),
cl::aliasopt(OutputFilename));
static cl::opt<SampleProfileFormat> OutputFormat(
"format", cl::desc("Format of output profile"), cl::init(SPF_Ext_Binary),
- cl::values(
- clEnumValN(SPF_Binary, "binary", "Binary encoding (default)"),
- clEnumValN(SPF_Ext_Binary, "extbinary", "Extensible binary encoding"),
- clEnumValN(SPF_Text, "text", "Text encoding"),
- clEnumValN(SPF_GCC, "gcc",
- "GCC encoding (only meaningful for -sample)")));
+ cl::values(clEnumValN(SPF_Binary, "binary", "Binary encoding (default)"),
+ clEnumValN(SPF_Ext_Binary, "extbinary",
+ "Extensible binary encoding"),
+ clEnumValN(SPF_Text, "text", "Text encoding"),
+ clEnumValN(SPF_GCC, "gcc",
+ "GCC encoding (only meaningful for -sample)")),
+ cl::cat(ProfGenCategory));
static cl::opt<bool> UseMD5(
"use-md5", cl::Hidden,
@@ -56,58 +61,57 @@ static cl::opt<int32_t, true> RecursionCompression(
static cl::opt<bool>
TrimColdProfile("trim-cold-profile",
cl::desc("If the total count of the profile is smaller "
- "than threshold, it will be trimmed."));
+ "than threshold, it will be trimmed."),
+ cl::cat(ProfGenCategory));
static cl::opt<bool> CSProfMergeColdContext(
"csprof-merge-cold-context", cl::init(true),
cl::desc("If the total count of context profile is smaller than "
"the threshold, it will be merged into context-less base "
- "profile."));
+ "profile."),
+ cl::cat(ProfGenCategory));
static cl::opt<uint32_t> CSProfMaxColdContextDepth(
"csprof-max-cold-context-depth", cl::init(1),
cl::desc("Keep the last K contexts while merging cold profile. 1 means the "
- "context-less base profile"));
+ "context-less base profile"),
+ cl::cat(ProfGenCategory));
static cl::opt<int, true> CSProfMaxContextDepth(
"csprof-max-context-depth",
cl::desc("Keep the last K contexts while merging profile. -1 means no "
"depth limit."),
- cl::location(llvm::sampleprof::CSProfileGenerator::MaxContextDepth));
+ cl::location(llvm::sampleprof::CSProfileGenerator::MaxContextDepth),
+ cl::cat(ProfGenCategory));
static cl::opt<double> ProfileDensityThreshold(
- "profile-density-threshold", llvm::cl::init(50),
- llvm::cl::desc("If the profile density is below the given threshold, it "
- "will be suggested to increase the sampling rate."),
- llvm::cl::Optional);
-static cl::opt<bool> ShowDensity("show-density", llvm::cl::init(false),
- llvm::cl::desc("show profile density details"),
- llvm::cl::Optional);
+ "profile-density-threshold", cl::init(50),
+ cl::desc("If the profile density is below the given threshold, it "
+ "will be suggested to increase the sampling rate."),
+ cl::Optional, cl::cat(ProfGenCategory));
+static cl::opt<bool> ShowDensity("show-density", cl::init(false),
+ cl::desc("show profile density details"),
+ cl::Optional, cl::cat(ProfGenCategory));
static cl::opt<int> ProfileDensityCutOffHot(
- "profile-density-cutoff-hot", llvm::cl::init(990000),
- llvm::cl::desc("Total samples cutoff for functions used to calculate "
- "profile density."));
+ "profile-density-cutoff-hot", cl::init(990000),
+ cl::desc("Total samples cutoff for functions used to calculate "
+ "profile density."),
+ cl::cat(ProfGenCategory));
static cl::opt<bool> UpdateTotalSamples(
- "update-total-samples", llvm::cl::init(false),
- llvm::cl::desc(
- "Update total samples by accumulating all its body samples."),
- llvm::cl::Optional);
+ "update-total-samples", cl::init(false),
+ cl::desc("Update total samples by accumulating all its body samples."),
+ cl::Optional, cl::cat(ProfGenCategory));
static cl::opt<bool> GenCSNestedProfile(
"gen-cs-nested-profile", cl::Hidden, cl::init(true),
cl::desc("Generate nested function profiles for CSSPGO"));
cl::opt<bool> InferMissingFrames(
- "infer-missing-frames", llvm::cl::init(true),
- llvm::cl::desc(
+ "infer-missing-frames", cl::init(true),
+ cl::desc(
"Infer missing call frames due to compiler tail call elimination."),
- llvm::cl::Optional);
-
-using namespace llvm;
-using namespace sampleprof;
-
-namespace llvm {
+ cl::Optional, cl::cat(ProfGenCategory));
namespace sampleprof {
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.h b/llvm/tools/llvm-profgen/ProfileGenerator.h
index 5e36128530cd9..d3e04563a81c2 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.h
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.h
@@ -17,9 +17,6 @@
#include <memory>
#include <unordered_set>
-using namespace llvm;
-using namespace sampleprof;
-
namespace llvm {
namespace sampleprof {
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index 6847ba1b21b1f..7dd5d3f773733 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -7,8 +7,10 @@
//===----------------------------------------------------------------------===//
#include "ProfiledBinary.h"
+
#include "ErrorHandling.h"
#include "MissingFrameInferrer.h"
+#include "Options.h"
#include "ProfileGenerator.h"
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
#include "llvm/Demangle/Demangle.h"
@@ -24,46 +26,51 @@
#define DEBUG_TYPE "load-binary"
-using namespace llvm;
-using namespace sampleprof;
+namespace llvm {
+
+using namespace object;
cl::opt<bool> ShowDisassemblyOnly("show-disassembly-only",
- cl::desc("Print disassembled code."));
+ cl::desc("Print disassembled code."),
+ cl::cat(ProfGenCategory));
cl::opt<bool> ShowSourceLocations("show-source-locations",
- cl::desc("Print source locations."));
+ cl::desc("Print source locations."),
+ cl::cat(ProfGenCategory));
static cl::opt<bool>
ShowCanonicalFnName("show-canonical-fname",
- cl::desc("Print canonical function name."));
+ cl::desc("Print canonical function name."),
+ cl::cat(ProfGenCategory));
static cl::opt<bool> ShowPseudoProbe(
"show-pseudo-probe",
- cl::desc("Print pseudo probe section and disassembled info."));
+ cl::desc("Print pseudo probe section and disassembled info."),
+ cl::cat(ProfGenCategory));
static cl::opt<bool> UseDwarfCorrelation(
"use-dwarf-correlation",
cl::desc("Use dwarf for profile correlation even when binary contains "
- "pseudo probe."));
+ "pseudo probe."),
+ cl::cat(ProfGenCategory));
static cl::opt<std::string>
DWPPath("dwp", cl::init(""),
cl::desc("Path of .dwp file. When not specified, it will be "
- "<binary>.dwp in the same directory as the main binary."));
+ "<binary>.dwp in the same directory as the main binary."),
+ cl::cat(ProfGenCategory));
static cl::list<std::string> DisassembleFunctions(
"disassemble-functions", cl::CommaSeparated,
cl::desc("List of functions to print disassembly for. Accept demangled "
- "names only. Only work with show-disassembly-only"));
+ "names only. Only work with show-disassembly-only"),
+ cl::cat(ProfGenCategory));
static cl::opt<bool>
KernelBinary("kernel",
- cl::desc("Generate the profile for Linux kernel binary."));
+ cl::desc("Generate the profile for Linux kernel binary."),
+ cl::cat(ProfGenCategory));
-extern cl::opt<bool> ShowDetailedWarning;
-extern cl::opt<bool> InferMissingFrames;
-
-namespace llvm {
namespace sampleprof {
static const Target *getTarget(const ObjectFile *Obj) {
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h
index 0588cb48b2af6..9c0bff591337a 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.h
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -41,15 +41,6 @@
#include <unordered_set>
#include <vector>
-namespace llvm {
-extern cl::opt<bool> EnableCSPreInliner;
-extern cl::opt<bool> UseContextCostForPreInliner;
-} // namespace llvm
-
-using namespace llvm;
-using namespace sampleprof;
-using namespace llvm::object;
-
namespace llvm {
namespace sampleprof {
@@ -303,34 +294,34 @@ class ProfiledBinary {
bool IsCOFF = false;
- void setPreferredTextSegmentAddresses(const ObjectFile *O);
+ void setPreferredTextSegmentAddresses(const object::ObjectFile *O);
template <class ELFT>
- void setPreferredTextSegmentAddresses(const ELFFile<ELFT> &Obj,
+ void setPreferredTextSegmentAddresses(const object::ELFFile<ELFT> &Obj,
StringRef FileName);
- void setPreferredTextSegmentAddresses(const COFFObjectFile *Obj,
+ void setPreferredTextSegmentAddresses(const object::COFFObjectFile *Obj,
StringRef FileName);
- void checkPseudoProbe(const ELFObjectFileBase *Obj);
+ void checkPseudoProbe(const object::ELFObjectFileBase *Obj);
- void decodePseudoProbe(const ELFObjectFileBase *Obj);
+ void decodePseudoProbe(const object::ELFObjectFileBase *Obj);
- void
- checkUseFSDiscriminator(const ObjectFile *Obj,
- std::map<SectionRef, SectionSymbolsTy> &AllSymbols);
+ void checkUseFSDiscriminator(
+ const object::ObjectFile *Obj,
+ std::map<object::SectionRef, SectionSymbolsTy> &AllSymbols);
// Set up disassembler and related components.
- void setUpDisassembler(const ObjectFile *Obj);
+ void setUpDisassembler(const object::ObjectFile *Obj);
symbolize::LLVMSymbolizer::Options getSymbolizerOpts() const;
// Load debug info of subprograms from DWARF section.
- void loadSymbolsFromDWARF(ObjectFile &Obj);
+ void loadSymbolsFromDWARF(object::ObjectFile &Obj);
// Load debug info from DWARF unit.
void loadSymbolsFromDWARFUnit(DWARFUnit &CompilationUnit);
// Create elf symbol to its start address mapping.
- void populateElfSymbolAddressList(const ELFObjectFileBase *O);
+ void populateElfSymbolAddressList(const object::ELFObjectFileBase *O);
// A function may be spilt into multiple non-continuous address ranges. We use
// this to set whether start a function range is the real entry of the
@@ -341,11 +332,12 @@ class ProfiledBinary {
void warnNoFuncEntry();
/// Dissassemble the text section and build various address maps.
- void disassemble(const ObjectFile *O);
+ void disassemble(const object::ObjectFile *O);
/// Helper function to dissassemble the symbol and extract info for unwinding
bool dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
- SectionSymbolsTy &Symbols, const SectionRef &Section);
+ SectionSymbolsTy &Symbols,
+ const object::SectionRef &Section);
/// Symbolize a given instruction pointer and return a full call context.
SampleContextFrameVector symbolize(const InstructionPointer &IP,
bool UseCanonicalFnName = false,
diff --git a/llvm/tools/llvm-profgen/llvm-profgen.cpp b/llvm/tools/llvm-profgen/llvm-profgen.cpp
index 3b974e25103ad..7e070a1ea6489 100644
--- a/llvm/tools/llvm-profgen/llvm-profgen.cpp
+++ b/llvm/tools/llvm-profgen/llvm-profgen.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "ErrorHandling.h"
+#include "Options.h"
#include "PerfReader.h"
#include "ProfileGenerator.h"
#include "ProfiledBinary.h"
@@ -21,7 +22,12 @@
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/VirtualFileSystem.h"
-static cl::OptionCategory ProfGenCategory("ProfGen Options");
+using namespace llvm;
+using namespace sampleprof;
+
+namespace llvm {
+
+cl::OptionCategory ProfGenCategory("ProfGen Options");
static cl::opt<std::string> PerfScriptFilen...
[truncated]
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
cl::cat(ProfGenCategory)
to non-hidden options so they show up in--help
output.Options.h
for options referenced in multiple files.